package com.admin.action.library_page_action;

import com.admin.Action;
import com.admin.dto.UserSendBean;
import com.admin.service.libraryservice.LibraryPage;
import com.admin.service.libraryservice.LibraryPageServiceImpl;
import com.google.gson.Gson;
import com.pojo.UserSendMsgBean;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

/**
 * 显示留言，发送到前端
 */
public class UserSendMsgAction extends Action {
    @Override
    public void execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        PrintWriter out=response.getWriter();
        HttpSession session = request.getSession();
        if(session.getAttribute("adminInfo")==null){
            out.println("<script>parent.window.location.href='error.html';</script>");
            return;
        }

        LibraryPage libraryPage = new LibraryPageServiceImpl();
        List<UserSendBean> list=libraryPage.UserSendMsg();
        Gson gson=new Gson();
        String msg=gson.toJson(list);
        out.print(msg);

    }
}
